Connecting to a Database

Once the .NET Client is installed, you can connect from your application to your database with a connection string.

The following example illustrates connecting to the underlying Sybase database using the .NET Client from an application developed in Visual Studio .NET. If you are connecting using a different ADO.NET data provider or connecting from the command line, the specific details vary.

If you are using Visual Studio .NET:

  1. In the Solution Explorer, right-click References; then, click Add Reference.

  2. Solution Explorer window

  3. Select the DataDirect Technologies SequeLink .NET Client in the component list.

  4. Add Reference dialog box with component list.

  5. Click OK. The Solution Explorer now includes a reference for the .NET Client.

  6. Solution Explorer window with the SequeLink data provider added.

  7. Check the beginning of your application. If the data provider's namespace is not present, add it, as shown in the following code fragments:
  8. C#

    // Access SequeLink Server

    using System.Data;

    using DDTek.SequeLink;

    Visual Basic

    ' Access SequeLink Server

    Imports System.Data

    Imports DDTek.SequeLink

  9. Add the connection information for your server and exception handling code, as shown in the following code fragments.
  10. C#

    DBConn = new SequeLinkConnection("Host=sydney;
    Port=19998;User ID=test01;Password=test01;
    Database=test");

    try

    {

    DBConn.Open();

    Console.WriteLine ("Connection successful!");

    }

    // Display any exceptions

    catch (SequeLinkException ex)

    {

    // Connection failed

    Console.WriteLine (ex.Message);

    return;

    }

    Visual Basic

    Dim Conn As New SequeLinkConnection("Host=bowhead;
    Port=19996;User ID=test01;Password=test01;
    Database=test")

    Try

    'Open the connection

    Conn.Open()

    MessageBox.Show("Connection successful!")

    Catch SLex As SequeLinkException

    'Connection failed

    MessageBox.Show(SLex.Message, "SequeLink Exception")

    End Try

  11. Close the connection.
  12. C#

    // Close the connection

    DBConn.Close();

    Visual Basic

    'Close the connection

    Conn.Close()